package study.distributed.shardingjdbc.strategy;

import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.util.Collection;

@Slf4j
public class CustomPreciseShardingAlgorithm implements PreciseShardingAlgorithm<Integer> {

    @Override
    public String doSharding(Collection<String> collection, PreciseShardingValue<Integer> preciseShardingValue) {
        log.info("preciseShardingValue:{}",preciseShardingValue.getColumnName()+":"+preciseShardingValue.getValue());
        for (String name : collection) {
            if (name.endsWith("1")) {
                return name;
            }
        }
        return null;
    }
}
